<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear="getOrderList"
          >
            <!-- - slot="append"，slot有插槽，还有位置的意思，这个属性的作用是：将button追加到input的后边
- 如果是slot="prepend"，那么就会将button放到input的前边 -->
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getOrderList"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column
          label="订单价格"
          prop="order_price"
          width="100"
        ></el-table-column>
        <el-table-column label="是否付款" prop="order_pay" width="100">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.order_pay === 1"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="是否发货"
          prop="is_send"
          width="100"
        ></el-table-column>
        <el-table-column label="下单时间" width="240" prop="create_time">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope>
            <!-- 选择区域按钮 -->
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              @click="showBox()"
            ></el-button>
            <!-- 展示物流按钮 -->
            <el-button
              type="success"
              size="mini"
              icon="el-icon-location"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="addressVisible" width="50%">
      <el-form
        :model="addressform"
        ref="addressRef"
        :rules="addressRules"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="addressform.address1"
            :options="CityData"
            :props="{ expandTrigger: 'hover' }"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细信息" prop="address2">
          <el-input v-model="addressform.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 查看物流对话框 -->
    <el-dialog title="提示" :visible.sync="progressVisible" width="50%">
      <span>这是一段信息</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="progressVisible = false">取 消</el-button>
        <el-button type="primary" @click="progressVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import CityData from './citydata'
export default {
  data() {
    return {
      addressform: {
        address1: '',
        address2: '',
      },
      addressRules: {
        address1: [
          { required: true, message: '请选择省市区县', trigger: 'blur' },
        ],
        address2: [
          { required: true, message: '请填写详细信息', trigger: 'blur' },
        ],
      }, // 级联样式框所需数据
      CityData,
      addressVisible: false,
      progressVisible: false,
      // 查看物流信息的数据属性
      progressInfo: [],
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      total: 0,
      orderList: [],
    }
  },
  methods: {
    // 获取数据列表
    async getOrderList() {
      const { data: res } = await this.$http.get('/orders', {
        params: this.queryInfo,
      })
      //   修改查询区域
      //   const querychar = this.queryInfo.query
      //   if (querychar.trim() !== '') {
      //       const resultStr = /\^${querychar}*/
      //       this.orderList.filter()
      //   }
      if (res.meta.status !== 200) {
        this.$message.error('获取数据列表失败')
      }
      this.orderList = res.data.goods
      this.total = res.data.total
      console.log(res.data)
    }, // 分页条目数改变事件
    handleSizeChange(val) {
      //   console.log(`每页 ${val} 条`)
      // 改变当前每页显示条目数
      this.queryInfo.pagesize = val
      //   重新调用getUserList()获取数据,刷新页面
      this.getOrderList()
    }, // 分页页码值改变事件
    handleCurrentChange(val) {
      //   console.log(`当前页: ${val}`)
      // 改变当前显示的页码值
      this.queryInfo.pagenum = val
      //   重新调用getUserList()获取数据,刷新页面
      this.getOrderList()
    }, // 选择地区对话框点击事件
    showBox() {
      this.addressVisible = true
    }, // 显示查看物流对话框 数据无法使用
    // async showProgress() {
    //   const { data: res } = await this.$http.get('/kuaidi')
    //   if (res.meta.status !== 200) {
    //     return this.$message.error('获取物流信息失败！')
    //   }
    //   this.progressInfo = res.data
    //   console.log(this.progressInfo)
    //   this.progressVisible = true
    // },
    handleChange(value) {
      console.log(value)
    },
  },
  created() {
    this.getOrderList()
  },
}
</script>
<style lang="less" scoped>
.el-table {
  margin-top: 15px;
}
.el-cascader {
  width: 100%;
}
</style>
